package tree;

/**
 * Add node.
 * @author Natchanon Hongladaromp
 *
 */
public class AddNode implements Tree
{
	private Tree left;
	private Tree right;

	/**
	 * Constructs for this node.
	 * @param left
	 * @param right
	 */
	public AddNode(Tree left, Tree right)
	{
		this.left = left;
		this.right = right;
	}

	@Override
	public double value()
	{
		return left.value() + right.value();
	}

	@Override
	public String toString(int order)
	{
		String r = left.toString(0) + " + " + right.toString(0);

		if (order > 0)
			return "(" + r + ")";
		else
			return r;
	}

	@Override
	public String toString()
	{
		return toString(-1);
	}
}
